package com.mshopping.app.manager;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * This class is used for 保存程序中的全局变量，不能存放过大的对象，如：bitmap 等
 * 
 * @author liuhuan
 * @version 1.0, 2013-8-31 下午10:58:33
 */
public class GlobleManager {

	private static Map<String, Object> globelObj = null;
	private static GlobleManager instance = null;

	private GlobleManager() {
		globelObj = Collections.synchronizedMap(new LinkedHashMap<String, Object>(10, 0.75f, true));
	}

	public static GlobleManager getInstance() {
		if (instance == null) {
			instance = new GlobleManager();
		}
		return instance;
	}

	public void put(String key, Object value) {
		if (globelObj.containsKey(key)) {
			globelObj.remove(key);
		}
		globelObj.put(key, value);
	}

	public void remove(String key) {
		if (globelObj.containsKey(key)) {
			globelObj.remove(key);
		}
	}

	public Object get(String key) {
		if (globelObj.containsKey(key)) {
			return globelObj.get(key);
		}
		return null;
	}

	public void clear() {
		globelObj.clear();
	}

	@Override
	protected void finalize() throws Throwable {
		super.finalize();
	}

	public void destory() {
		globelObj.clear();
		instance = null;
		System.gc();
	}
}
